package com.cn.dao.model;

import java.util.ArrayList;
import java.util.Date;

import com.cn.bean.SimpleMap;

/**
 * FUN: 数据块
 * 
 * @author sushy
 * @date 2016-3-23
 */
public class NamedDataBlock extends ArrayList<SimpleMap> {

	private static final long serialVersionUID = -4602391222829579642L;

	private boolean isOutOfBounds(int index) {
		return (index < 0 || index >= size());
	}

	public long getLong(int index, String colName) {
		if (isOutOfBounds(index)) {
			return 0;
		}
		return get(index).getLong(colName);
	}

	public String getString(int index, String colName) {
		if (isOutOfBounds(index)) {
			return null;
		}
		return get(index).getString(colName);
	}

	public Date getDate(int index, String colName) {
		if (isOutOfBounds(index)) {
			return null;
		}
		return get(index).getDate(colName);
	}

	public void add(int i, String colName, String value) {
		add(i, colName, (Object) value);
	}

	public void add(int i, String colName, long value) {
		add(i, colName, (Object) value);
	}

	public void add(int i, String colName, double value) {
		add(i, colName, (Object) value);
	}

	public void add(int i, String colName, Date value) {
		add(i, colName, (Object) value);
	}

	private void add(int i, String colName, Object value) {
		while (i >= size()) {
			add(new SimpleMap());
		}
		get(i).put(colName, value);
	}

}
